//
//  RNOLHomePageView.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/8.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLHomePageView.h"
#import "RNOLHomeNoticeView.h"
#import "RNOLHomeIndexView.h"
#import "RNOLHomeNoobSpecialView.h"

@interface RNOLHomePageView()<SDCycleScrollViewDelegate>

@property (nonatomic,strong) SDCycleScrollView *bannerView;
@property (nonatomic,strong) RNOLHomeNoticeView *noticeView;
@property (nonatomic,strong) RNOLHomeIndexView *indexIconView;
@property (nonatomic,strong) UIView *noodContainerView;
@property (nonatomic,strong) RNOLHomeNoobSpecialView *noobSpecialView;
@property (nonatomic,strong) RNOLBottomDescriptionFooter *footer;

@end


@implementation RNOLHomePageView


- (SDCycleScrollView *)bannerView{
    if (!_bannerView) {
        _bannerView = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , 150)];
        _bannerView.imageURLStringsGroup = @[@"https://www.rongniu360.com/cmsImages/51269F32CCA3D60FC18EC7C727284768.jpg"];
        _bannerView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
        _bannerView.showPageControl = YES;
        _bannerView.delegate = self;
        _bannerView.autoScrollTimeInterval = 2;
        _bannerView.pageDotColor = [UIColor whiteColor];
        _bannerView.pageControlDotSize = CGSizeMake(8, 8);
        _bannerView.currentPageDotColor = RGB(191, 151, 20);
    }
    return _bannerView;
}

- (RNOLHomeNoticeView *)noticeView{
    if (!_noticeView) {
        _noticeView = [[RNOLHomeNoticeView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.bannerView.frame), KWIDTH , 25)];
        _noticeView.backgroundColor = KWhiteColor;
        _noticeView.msgArray = @[@"习近平的网络强国策",@"李克强主持国务院常务会七措施提高职业技能",@"商务部再谈美制裁中兴：希望美方不要自作聪明",@"韩公布韩朝首脑会谈总统随行人员名单 | 韩朝商定首脑会晤握手等直播"];
    }
    return _noticeView;
    
}

- (RNOLHomeIndexView *)indexIconView{
    if (!_indexIconView) {
        NSArray *titles =  @[@"产品介绍",@"平台数据",@"安全保障",@"新手指引"];
        NSArray *images = @[@"rnol_home_icon001",@"rnol_home_icon002",@"rnol_home_icon003",@"rnol_home_icon004"];
        _indexIconView = [[RNOLHomeIndexView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.noticeView.frame)+15, KWIDTH , 100) Titles:titles images:images callBack:^(NSInteger index) {
            if (self.delegate && [self.delegate respondsToSelector:@selector(indexIconViewClickEventWithModel:atInex:)]) {
                [self.delegate indexIconViewClickEventWithModel:nil atInex:index];
            }
        }];
    }
    return _indexIconView;
}

- (UIView *)noodContainerView{
    if (!_noodContainerView) {
        _noodContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.indexIconView.frame)+15, KWIDTH , 350)];
        _noodContainerView.backgroundColor = KWhiteColor;
    }
    return _noodContainerView;
}

- (RNOLHomeNoobSpecialView *)noobSpecialView{
    if (!_noobSpecialView) {
        _noobSpecialView = [RNOLHomeNoobSpecialView FromXIB];
        _noobSpecialView.frame = self.noodContainerView.bounds;
        _noobSpecialView.backgroundColor = KWhiteColor ;
    }
    return _noobSpecialView;
}

- (RNOLBottomDescriptionFooter *)footer{
    if (!_footer) {
        _footer = [RNOLBottomDescriptionFooter footer];
        _footer.y = CGRectGetMaxY(self.noodContainerView.frame);
    }
    return _footer;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
        [self actionEvents];
    }
    return self;
}


- (void)setup{
    [self addSubview: self.bannerView];
    [self addSubview: self.noticeView];
    [self addSubview: self.indexIconView];
    [self addSubview: self.noodContainerView];
    [self.noodContainerView addSubview: self.noobSpecialView];
    [self addSubview: self.footer];
}


- (CGFloat)homepageMaxHeight{
    return CGRectGetMaxY(self.footer.frame);
}

#pragma mark- 事件
- (void)actionEvents{
    @weakify(self);
    [self.noticeView setMoreBlock:^{
        @strongify(self);
        if (self.delegate && [self.delegate respondsToSelector:@selector(noticeClickMoreEventAction)]) {
            [self.delegate noticeClickMoreEventAction];
        }
    }];
    
    [self.noticeView setNoticeIndexBlock:^(NSInteger index) {
        @strongify(self);
        if (self.delegate && [self.delegate respondsToSelector:@selector(noticeClickEventWithModel:atInex:)]) {
            [self.delegate noticeClickEventWithModel:nil atInex: index];
        }
    }];
    
    [self.noobSpecialView setInverstBlock:^{
        @strongify(self);
        if (self.delegate && [self.delegate respondsToSelector:@selector(noobSpecialViewClickEventAction)]) {
            [self.delegate noobSpecialViewClickEventAction];
        }
    }];
}


#pragma mark- <SDCycleScrollViewDelegate>
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    if (self.delegate && [self.delegate respondsToSelector:@selector(bannerClickEventWithModel:atInex:)]) {
        [self.delegate bannerClickEventWithModel:nil atInex:index];
    }    
}



@end
